class Animal {
    public String name;
    public int age;

    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public void eat() {
        System.out.println(name + "正在吃！");
    }

    @Override
    public String toString() {
        return "Animal{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}
class Dog extends Animal {
    public Dog(String name, int age) {
        super(name, age);
    }

    public void wangWang() {
        System.out.println(name + "正在旺旺！");
    }
    public void eat() {
        System.out.println(name+"正在吃狗粮！！");
    }
}
class Bird extends Animal{
    public Bird(String name,int age){
        super(name, age);
    }

    public void fly() {
        System.out.println(name+"正在飞！");
    }
}

public class Test{

    public static void main(String[] args) {
        Animal animal = new Dog("小狗",10);
        animal.eat();
//        animal.wangWang();
    }
    /*
    有三种方式可以向上转型
    1.直接赋值；
    2.方法传参的方式
    3.返回值

     */
    public static void main2(String[] args) {
        //向上转型；
        Animal animal1 = new Dog("小狗",10);
        Animal animal2 = new Dog("小鸟",10);

        Dog dog = new Dog("小狗",10);
        Bird bird = new Bird("小鸟",10);
        //方法传参；
        func1(dog);
        func1(bird);
        //
        Animal animal3 = func2();
        Animal animal4 = func3();
    }

    public static Animal func2() {
        return new Dog("小鸟",10);

    }

    public static Bird func3() {
        return new  Bird("小鸟",10);
    }

    public static int func4() {
//        return 10;
        int a = 10;
        return a;

    }

    public static void func1(Animal animal) {
    }

    public static void main1(String[] args) {
        Dog dog = new Dog("小狗",10);
        dog.eat();
        dog.wangWang();
        System.out.println("======");
        Animal animal = new Animal("animal",10);
        animal.eat();
        //
    }
}




